# Maintainer: dorphell <dorphell@archlinux.org>
# Contributor: Jose Javier  <jojapa@terra.es>

pkgname=tftp-hpa
pkgver=5.2
pkgrel=10
pkgdesc="Official tftp server"
arch=('x86_64')
url="https://www.kernel.org/pub/software/network/tftp/tftp-hpa/"
license=('BSD')
backup=('etc/conf.d/tftpd')
install='tftpd.install'
depends=('readline>=6.0.00')
source=(https://www.kernel.org/pub/software/network/tftp/tftp-hpa/$pkgname-$pkgver.tar.gz 
       LICENSE
       tftpd.conf
       tftpd.service
       tftpd.socket
       tftp-hpa-0.49-fortify-strcpy-crash.patch)
sha256sums=('acc04dde662491e3092565ecf9bde504c47dbb1bb0408366009b138fe7754cab'
            '628639fd20f1716bfd71a8bc4bf983fd16eb004cc1ec5a4abf99e6618cfcb870'
            'f4bbc89a460da40f0914ebf55edce0306090e11073ea31f6ffc11d62b527ece4'
            'da79f8d3791daa91624677d4b3ace91b63965c87c6791e3ce0155637609c6cb1'
            '22af7da2cb61a119cfcba65f740ff0a35157204218dcbdbf13e14dbf74043ff2'
            '4862bc4bf61b8abbcfc22c4bc6714a5cf8d52e9db1b1d7f7b4c5059ef89ced2f')

prepare() {
  cd ${pkgname}-${pkgver}
  # fix #28103
  patch -Np1 -i ../tftp-hpa-0.49-fortify-strcpy-crash.patch
}

build() {
  cd ${pkgname}-${pkgver}
  CFLAGS+=' -fcommon' # https://wiki.gentoo.org/wiki/Gcc_10_porting_notes/fno_common
  ./configure --prefix=/usr --mandir=/usr/share/man --sbindir=/usr/bin --without-tcpwrappers 
  make
}

package() {
  cd ${pkgname}-${pkgver}
  make INSTALLROOT="${pkgdir}" install
  install -D -m644 "${srcdir}/tftpd.conf" "$pkgdir/etc/conf.d/tftpd"
  install -d "${pkgdir}/srv/tftp"
  install -D -m644 "${srcdir}/tftpd.service" "${pkgdir}/usr/lib/systemd/system/tftpd.service"
  install -D -m644 "${srcdir}/tftpd.socket" "${pkgdir}/usr/lib/systemd/system/tftpd.socket"
  install -D -m644 "${srcdir}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  # Remove conflict with iputils
  rm "${pkgdir}/usr/share/man/man8/tftpd.8"  
}
